﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace LunwenYun.Infrastructure.Entities.Repository
{
    [Table("T_ApplySheet")]
    public class T_ApplySheet :IEntity<T_ApplySheet>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public int PerodicalId { get; set; }

        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string Username { get; set; }

        [Column(TypeName="text")]
        public string ApplyContent { get; set; }

        public DateTime ApplyDate { get; set; }
        /// <summary>
        /// 0:申请，1：同意，2：拒绝
        /// </summary>
        public int Status { get; set; }
        public DateTime HandleDate { get; set; }

        public override T_ApplySheet Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.Id == id);
        }

        public override T_ApplySheet Find(System.Linq.Expressions.Expression<Func<T_ApplySheet, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.ApplySheet.FirstOrDefault(where);
                this.ApplyContent = item.ApplyContent;
                this.ApplyDate = item.ApplyDate;
                this.Id = item.Id;
                this.PerodicalId = item.PerodicalId;
                this.Username = item.Username;
                this.Status = item.Status;
                this.HandleDate = item.HandleDate;
                return this;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_ApplySheet, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.ApplySheet.Any(where);
            }
        }
    }
}
